/**
  **************************************************************************
  * @file     at32f421_int.c
  * @brief    main interrupt service routines.
  **************************************************************************
  *                       Copyright notice & Disclaimer
  *
  * The software Board Support Package (BSP) that is made available to
  * download from Artery official website is the copyrighted work of Artery.
  * Artery authorizes customers to use, copy, and distribute the BSP
  * software and its related documentation for the purpose of design and
  * development in conjunction with Artery microcontrollers. Use of the
  * software is governed by this copyright notice and the following disclaimer.
  *
  * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  *
  **************************************************************************
  */

/* includes ------------------------------------------------------------------*/
#include "at32f421_int.h"
#include "system_task.h"
#include "fldrv_ertc.h"
#include "flapp_system.h"
#include "flapp_display.h"
/** @addtogroup AT32F421_periph_examples
  * @{
  */

/** @addtogroup 421_FLASH_write_read
  * @{
  */

/**
  * @brief  this function handles nmi exception.
  * @param  none
  * @retval none
  */
void NMI_Handler(void)
{
}

/**
  * @brief  this function handles hard fault exception.
  * @param  none
  * @retval none
  */
void HardFault_Handler(void)
{
  /* go to infinite loop when hard fault exception occurs */
  while(1)
  {
		at32_led_toggle(LED4);
  }
}

/**
  * @brief  this function handles memory manage exception.
  * @param  none
  * @retval none
  */
void MemManage_Handler(void)
{
  /* go to infinite loop when memory manage exception occurs */
  while(1)
  {
  }
}

/**
  * @brief  this function handles bus fault exception.
  * @param  none
  * @retval none
  */
void BusFault_Handler(void)
{
  /* go to infinite loop when bus fault exception occurs */
  while(1)
  {
  }
}

/**
  * @brief  this function handles usage fault exception.
  * @param  none
  * @retval none
  */
void UsageFault_Handler(void)
{
  /* go to infinite loop when usage fault exception occurs */
  while(1)
  {
  }
}

/**
  * @brief  this function handles svcall exception.
  * @param  none
  * @retval none
  */
void SVC_Handler(void)
{
}

/**
  * @brief  this function handles debug monitor exception.
  * @param  none
  * @retval none
  */
void DebugMon_Handler(void)
{
}

/**
  * @brief  this function handles pendsv_handler exception.
  * @param  none
  * @retval none
  */
void PendSV_Handler(void)
{
}
/**
  * @brief  this function handles dma1_channel1 handler.
  * @param  none
  * @retval none
  */
extern u8 dma_trans_complete_flag;
void DMA1_Channel1_IRQHandler(void)
{
  if(dma_flag_get(DMA1_FDT1_FLAG) != RESET)
  {
    dma_flag_clear(DMA1_FDT1_FLAG);
    dma_trans_complete_flag++;
  }
}

/**
  * @brief  this function handles systick handler.
  * @param  none
  * @retval none
  */
void SysTick_Handler(void)
{
	System_Tick_Counter++;
}

/**
  * @brief  exint0 interrupt handler
  * @param  none
  * @retval none
  */
void EXINT1_0_IRQHandler(void)
{
  if(exint_interrupt_flag_get(EXINT_LINE_0) != RESET)
  {
    exint_flag_clear(EXINT_LINE_0);
  }
}
/**
  * @brief  exint0 interrupt handler
  * @param  none
  * @retval none
  */
void EXINT15_4_IRQHandler(void)
{
  if(exint_interrupt_flag_get(EXINT_LINE_4) != RESET || \
		 exint_interrupt_flag_get(EXINT_LINE_6) != RESET || \
		 exint_interrupt_flag_get(EXINT_LINE_11) != RESET || \
		 exint_interrupt_flag_get(EXINT_LINE_14) != RESET || \
		 exint_interrupt_flag_get(EXINT_LINE_15) != RESET)
  {
    exint_flag_clear(EXINT_LINE_4);
		exint_flag_clear(EXINT_LINE_6);
		exint_flag_clear(EXINT_LINE_11);
		exint_flag_clear(EXINT_LINE_14);
		exint_flag_clear(EXINT_LINE_15);
  }
}
/**
  * @brief  this function handles ertc alarms interrupt request.
  * @param  none
  * @retval none
  */
void ERTC_IRQHandler(void)
{
  if(ertc_interrupt_flag_get(ERTC_ALAF_FLAG) != RESET)
  {
		flapp_set_led_refresh();					
    /* clear alarm flag */
    ertc_flag_clear(ERTC_ALAF_FLAG);

    /* clear exint flag */
    exint_flag_clear(EXINT_LINE_17);
  }
}
/**
  * @}
  */

/**
  * @}
  */
